
#include <iostream>
#include <sstream>
using namespace std;

typedef struct Node{
	int value;
	struct Node *left;
	struct Node *right;
} node,*BiTree;

int getRootIndex(int A[],int l,int r, int key){
	for(int i=l;i<r;i++){
		if(A[i]==key)
			return i;
	}
	return -1;
}

int n,*mos,*aos;

void createBiTree(BiTree &bitree, int ml,int mr, int al,int ar)
{
	if(ml<mr){
		bitree = new node;
		bitree->value = aos[ar-1];
		bitree->left = nullptr;
		bitree->right= nullptr;
		int index = getRootIndex(mos,ml,mr,aos[ar-1]);
		createBiTree(bitree->left, ml,index,al,al+index-ml);
		createBiTree(bitree->right,index+1,mr,al+index-ml,ar-1);
	}
}

node **levelTraversal(BiTree bt){
	node** los = new node*[n];
	int t,s;
	t = 0, s = 1,los[0] = bt;
	while( s>0 ){
		if(los[t]->left!=nullptr){
			los[t+s] = los[t]->left;
			s++;
		}
		if(los[t]->right!=nullptr){
			los[t+s] = los[t]->right;
			s++;
		}
		t++,s--;
	}
	return los;
}

int main()
{
	cin>>n;
	mos = new int[n];
	aos = new int[n];
	
	for(int i=0; i<n; i++){
		cin>>aos[i];
	}
	for(int i=0; i<n; i++){
		cin>>mos[i];
	}
	BiTree bt;
	createBiTree(bt,0,n,0,n);
	node ** ns = levelTraversal(bt);
	
	for(int i=0; i<n-1; i++){
		cout<<ns[i]->value<<" ";
	}
	cout<<ns[n-1]->value;
	return 0;
}
